package com.atguigu.web;

import com.atguigu.pojo.Cart;
import com.atguigu.pojo.User;
import com.atguigu.service.OrderService;
import com.atguigu.service.impl.OrderServiceImp;
import com.atguigu.utils.JDBCUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Chen
 * @Description
 * @Version
 * @create 2021-11-21-14:47
 */
@WebServlet("/getOrder")
public class OrderServlet extends BaseServlet{
    private OrderService orderService = new OrderServiceImp();
    /**
     * 生成订单
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void createOrder(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Cart cart = (Cart) req.getSession().getAttribute("cart");

        User loginUser = (User) req.getSession().getAttribute("user");
        Integer userId = loginUser.getId();


        String orderId = orderService.createOrder(cart, userId);
        req.getSession().setAttribute("orderId", orderId);

        resp.sendRedirect("view/order/orderSuccess.jsp");
    }
}
